1 package org.smartcomps.twister.engine.core.definition;
2
3 import junit.framework.TestCase;
4 import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
5 import net.sf.hibernate.cfg.Configuration;
6 import org.smartcomps.twister.common.transaction.TransactionManager;
7 import org.smartcomps.twister.common.lifecycle.LifecycleManager;
8 import org.smartcomps.twister.engine.priv.core.definition.ActivityFactory;
9 import org.smartcomps.twister.engine.priv.core.definition.Sequence;
10 import org.smartcomps.twister.engine.priv.core.definition.Invoke;
11 import org.smartcomps.twister.engine.priv.core.definition.ProcessFactory;
12 import org.smartcomps.twister.engine.priv.core.definition.Activity;
13 import org.smartcomps.twister.engine.priv.core.definition.Terminate;
14 import org.smartcomps.twister.util.BeanTester;
15
16 /***
17 * To test the terminate we create a sequence containing one terminate and
18 * two invokes making sure that when executing the invokes are not.
19 */
20 public class TestTerminate extends TestCase {
21
22 public static Sequence testSequence = null;
23
24 private TestProcess testProcess = new TestProcess();
25 private BeanTester beanTester = new BeanTester(new String[] {"Id", "Index"});
26
27 protected void setUp() throws Exception {
28 LifecycleManager.getLifecycleManager().createResources();
29 LifecycleManager.getLifecycleManager().startResources();
30
31 SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
32 schemaExport.create(true, true);
33
34 TransactionManager.beginTransaction();
35 testProcess.testCreate();
36 }
37
38 protected void tearDown() throws Exception {
39 TransactionManager.commitTransaction();
40
41 LifecycleManager.getLifecycleManager().stopResources();
42 LifecycleManager.getLifecycleManager().destroyResources();
43 }
44
45 public void testCreate() throws Exception {
46 testSequence = (Sequence) ActivityFactory.createActivity(Sequence.class, TestProcess.testProcess);
47 Terminate terminate = (Terminate) ActivityFactory.createActivity(Terminate.class, testSequence);
48 beanTester.initializeProperties("terminate", terminate);
49 Invoke invoke2 = (Invoke) ActivityFactory.createActivity(Invoke.class, testSequence);
50 beanTester.initializeProperties("invoke2", invoke2);
51 Invoke invoke3 = (Invoke) ActivityFactory.createActivity(Invoke.class, testSequence);
52 beanTester.initializeProperties("invoke3", invoke3);
53
54 TransactionManager.commitTransaction();
55 TransactionManager.beginTransaction();
56
57 Sequence resultSeq = (Sequence) ProcessFactory.getByName(TestProcess.testProcess.getName()).getActivity();
58 assertNotNull("Sequence process is null", resultSeq.getProcess());
59 Activity act1 = (Activity) resultSeq.getActivities().get(0);
60 assertTrue("First activity in the sequence is not a Terminate", act1 instanceof Terminate);
61 assertTrue("First activity attributes have been changed", beanTester.testValues("terminate", act1));
62 Activity act2 = (Activity) resultSeq.getActivities().get(1);
63 assertTrue("Second activity in the sequence is not an Invoke", act2 instanceof Invoke);
64 assertTrue("Second activity attributes have been changed", beanTester.testValues("invoke2", act2));
65 Activity act3 = (Activity) resultSeq.getActivities().get(2);
66 assertTrue("Third activity in the sequence is not an Invoke", act3 instanceof Invoke);
67 assertTrue("Third activity attributes have been changed", beanTester.testValues("invoke3", act3));
68
69 }
70
71 }
This page was automatically generated by Maven